package menu

import (
	"gitee.com/micro-plat/sso/apiserver/api/modules/biz/menu"
	"gitee.com/micro-plat/sso/apiserver/api/modules/const/field"
	"github.com/micro-plat/hydra"
)

//MemberHandler 获取菜单信息处理服
type MenuHandler struct {
	requiredFields []string
}

func NewMenuHandler() *MenuHandler {
	return &MenuHandler{
		requiredFields: []string{field.UserID, field.Ident},
	}
}

//GetHandle  获取菜单信息
func (u *MenuHandler) GetHandle(ctx hydra.IContext) (r interface{}) {

	ctx.Log().Info("--------获取菜单数据--------")

	ctx.Log().Info("1.检查必须字段")
	if err := ctx.Request().Check(u.requiredFields...); err != nil {
		return err
	}

	ctx.Log().Info("2.获取菜单信息")
	system, err := menu.GetMenusByUserID(
		ctx.Request().GetString(field.UserID),
		ctx.Request().GetString(field.Ident))
	if err != nil {
		return err
	}
	return system
}
